//
//  ResponseModel.swift
//  Swift-Codedase
//
//  Created by 徐先生 on 2023/2/27.
//

import Foundation
import SwiftyJSON
import HandyJSON

class ResponseModel: HandyJSON {
    
    var code: Int = -999
    var message: String = ""
    var success: Bool {
        code == successCode || code == 200
    }
    
    // json 数据,保存response.data
    var dataSources: JSON?
    // 字典类型的数据
    var dataDictionary: [String: Any] {
        get { dataSources?.dictionaryObject ?? [:] }
        set { dataSources = JSON(newValue as Any) }
    }
    // 数组类型的数据
    var dataArray: [Any] {
        get { dataSources?.arrayObject ?? [] }
        set { dataSources = JSON(newValue as Any) }
    }
    
    var dataString: String {
        get { dataSources?.string ?? "" }
        set { dataSources = JSON(newValue as Any) }
    }
    
    /// true:第一页 false: 其他
    var firstPage: Bool = false
    /// true:最后一页 false: 其他
    var lastPage: Bool = false
    
    required init() {}
    // 子类使用的时候要重写该方法
    func mapping(mapper: HelpingMapper) {
        mapper <<< [
            message <-- ["msg", "message"]
        ]
    }
    func didFinishMapping() {}
    
}
